package org.jivesoftware.smackx.filetransfer;

public abstract class FileTransfer
{
  private static final int BUFFER_SIZE = 8192;
  protected long amountWritten;
  private Error error;
  private Exception exception;
  private String fileName;
  private String filePath;
  private long fileSize;
  protected FileTransferNegotiator negotiator;
  private String peer;
  private Status status = Status.initial;
  private final Object statusMonitor = new Object();
  protected String streamID;

  protected FileTransfer(String paramString1, String paramString2, FileTransferNegotiator paramFileTransferNegotiator)
  {
    this.amountWritten = -1L;
    this.peer = paramString1;
    this.streamID = paramString2;
    this.negotiator = paramFileTransferNegotiator;
  }

  public abstract void cancel();

  public long getAmountWritten()
  {
    return this.amountWritten;
  }

  public Error getError()
  {
    return this.error;
  }

  public Exception getException()
  {
    return this.exception;
  }

  public String getFileName()
  {
    return this.fileName;
  }

  public String getFilePath()
  {
    return this.filePath;
  }

  public long getFileSize()
  {
    return this.fileSize;
  }

  public String getPeer()
  {
    return this.peer;
  }

  public double getProgress()
  {
    double d;
    if ((this.amountWritten <= 0L) || (this.fileSize <= 0L))
      d = 0D;
    while (true)
    {
      return d;
      d = this.amountWritten / this.fileSize;
    }
  }

  public Status getStatus()
  {
    return this.status;
  }

  public String getStreamID()
  {
    return this.streamID;
  }

  public boolean isDone()
  {
    int i;
    if ((this.status != Status.cancelled) && (this.status != Status.error) && (this.status != Status.complete) && (this.status != Status.refused))
      i = 0;
    while (true)
    {
      return i;
      i = 1;
    }
  }

  protected void setError(Error paramError)
  {
    this.error = paramError;
  }

  protected void setException(Exception paramException)
  {
    this.exception = paramException;
  }

  protected void setFileInfo(String paramString, long paramLong)
  {
    this.fileName = paramString;
    this.fileSize = paramLong;
  }

  protected void setFileInfo(String paramString1, String paramString2, long paramLong)
  {
    this.filePath = paramString1;
    this.fileName = paramString2;
    this.fileSize = paramLong;
  }

  protected void setStatus(Status paramStatus)
  {
    synchronized (this.statusMonitor)
    {
      this.status = paramStatus;
      return;
    }
  }

  // ERROR //
  protected boolean updateStatus(Status paramStatus1, Status paramStatus2)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 43	org/jivesoftware/smackx/filetransfer/FileTransfer:statusMonitor	Ljava/lang/Object;
    //   4: astore_3
    //   5: aload_3
    //   6: monitorenter
    //   7: aload_1
    //   8: aload_0
    //   9: getfield 41	org/jivesoftware/smackx/filetransfer/FileTransfer:status	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   12: if_acmpeq +11 -> 23
    //   15: aload_3
    //   16: monitorexit
    //   17: iconst_0
    //   18: istore 5
    //   20: goto +23 -> 43
    //   23: aload_0
    //   24: aload_2
    //   25: putfield 41	org/jivesoftware/smackx/filetransfer/FileTransfer:status	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   28: aload_3
    //   29: monitorexit
    //   30: iconst_1
    //   31: istore 5
    //   33: goto +10 -> 43
    //   36: astore 4
    //   38: aload_3
    //   39: monitorexit
    //   40: aload 4
    //   42: athrow
    //   43: iload 5
    //   45: ireturn
    //
    // Exception table:
    //   from	to	target	type
    //   7	40	36	finally
  }

  // ERROR //
  protected void writeToStream(java.io.InputStream paramInputStream, java.io.OutputStream paramOutputStream)
    throws org.jivesoftware.smack.XMPPException
  {
    // Byte code:
    //   0: sipush 8192
    //   3: newarray byte
    //   5: astore_3
    //   6: iconst_0
    //   7: istore 4
    //   9: aload_0
    //   10: lconst_0
    //   11: putfield 47	org/jivesoftware/smackx/filetransfer/FileTransfer:amountWritten	J
    //   14: aload_2
    //   15: aload_3
    //   16: iconst_0
    //   17: iload 4
    //   19: invokevirtual 116	java/io/OutputStream:write	([BII)V
    //   22: aload_0
    //   23: aload_0
    //   24: getfield 47	org/jivesoftware/smackx/filetransfer/FileTransfer:amountWritten	J
    //   27: iload 4
    //   29: i2l
    //   30: ladd
    //   31: putfield 47	org/jivesoftware/smackx/filetransfer/FileTransfer:amountWritten	J
    //   34: aload_1
    //   35: aload_3
    //   36: invokevirtual 122	java/io/InputStream:read	([B)I
    //   39: istore 7
    //   41: iload 7
    //   43: istore 4
    //   45: iload 4
    //   47: bipush 255
    //   49: if_icmpeq +16 -> 65
    //   52: aload_0
    //   53: invokevirtual 124	org/jivesoftware/smackx/filetransfer/FileTransfer:getStatus	()Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   56: getstatic 85	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:cancelled	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   59: invokevirtual 128	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:equals	(Ljava/lang/Object;)Z
    //   62: ifeq -48 -> 14
    //   65: aload_0
    //   66: invokevirtual 124	org/jivesoftware/smackx/filetransfer/FileTransfer:getStatus	()Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   69: getstatic 85	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:cancelled	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   72: invokevirtual 128	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:equals	(Ljava/lang/Object;)Z
    //   75: ifne +39 -> 114
    //   78: aload_0
    //   79: invokevirtual 130	org/jivesoftware/smackx/filetransfer/FileTransfer:getError	()Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;
    //   82: getstatic 133	org/jivesoftware/smackx/filetransfer/FileTransfer$Error:none	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;
    //   85: if_acmpne +29 -> 114
    //   88: aload_0
    //   89: getfield 47	org/jivesoftware/smackx/filetransfer/FileTransfer:amountWritten	J
    //   92: aload_0
    //   93: getfield 74	org/jivesoftware/smackx/filetransfer/FileTransfer:fileSize	J
    //   96: lcmp
    //   97: ifeq +17 -> 114
    //   100: aload_0
    //   101: getstatic 87	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:error	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   104: invokevirtual 135	org/jivesoftware/smackx/filetransfer/FileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
    //   107: aload_0
    //   108: getstatic 138	org/jivesoftware/smackx/filetransfer/FileTransfer$Error:connection	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;
    //   111: putfield 60	org/jivesoftware/smackx/filetransfer/FileTransfer:error	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;
    //   114: return
    //   115: astore 5
    //   117: new 108	org.jivesoftware.smack.XMPPException
    //   120: dup
    //   121: ldc 140
    //   123: aload 5
    //   125: invokespecial 143	org.jivesoftware.smack.XMPPException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   128: athrow
    //   129: astore 6
    //   131: new 108	org.jivesoftware.smack.XMPPException
    //   134: dup
    //   135: ldc 145
    //   137: aload 6
    //   139: invokespecial 143	org.jivesoftware.smack.XMPPException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   142: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   14	22	115	java/io/IOException
    //   34	41	129	java/io/IOException
  }

  public static enum Error
  {
    private final String msg;

    static
    {
      bad_file = new Error("bad_file", 2, "The provided file to transfer does not exist or could not be read.");
      no_response = new Error("no_response", 3, "The remote user did not respond or the connection timed out.");
      connection = new Error("connection", 4, "An error occured over the socket connected to send the file.");
      stream = new Error("stream", 5, "An error occured while sending or recieving the file.");
      Error[] arrayOfError = new Error[6];
      arrayOfError[0] = none;
      arrayOfError[1] = not_acceptable;
      arrayOfError[2] = bad_file;
      arrayOfError[3] = no_response;
      arrayOfError[4] = connection;
      arrayOfError[5] = stream;
      ENUM$VALUES = arrayOfError;
    }

    public String getMessage()
    {
      return this.msg;
    }

    public String toString()
    {
      return this.msg;
    }
  }

  public static enum Status
  {
    private String status;

    static
    {
      negotiating_stream = new Status("negotiating_stream", 4, "Negotiating Stream");
      negotiated = new Status("negotiated", 5, "Negotiated");
      in_progress = new Status("in_progress", 6, "In Progress");
      complete = new Status("complete", 7, "Complete");
      cancelled = new Status("cancelled", 8, "Cancelled");
      Status[] arrayOfStatus = new Status[9];
      arrayOfStatus[0] = error;
      arrayOfStatus[1] = initial;
      arrayOfStatus[2] = negotiating_transfer;
      arrayOfStatus[3] = refused;
      arrayOfStatus[4] = negotiating_stream;
      arrayOfStatus[5] = negotiated;
      arrayOfStatus[6] = in_progress;
      arrayOfStatus[7] = complete;
      arrayOfStatus[8] = cancelled;
      ENUM$VALUES = arrayOfStatus;
    }

    public String toString()
    {
      return this.status;
    }
  }
}